package cn.edu.hziee;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;

public class RequestParamsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        String userName = request.getParameter("userName");
        String pwd = request.getParameter("pwd");
        String re_pwd = request.getParameter("re_pwd");
        String[] beers = request.getParameterValues("beer");
        out.println("userName:"+userName);
        out.println("pwd："+pwd);
        out.println("re_pwd:"+re_pwd);
        if (beers!=null) {
            for (String beer : beers) {
                out.println("beer:"+beer);
            }
        }
       /*Enumeration<String> em = request.getParameterNames();
        while (em.hasMoreElements()) {
            String paramName = em.nextElement();
            String[] paramValues = request.getParameterValues(paramName);
            for (String paramValue : paramValues) {
                out.println(paramName + "=" + paramValue);
            }
        }
        Map<String,String[]> map = request.getParameterMap();
        Set<String> keys = map.keySet();
        for (String key : keys) {
            String[] values = map.get(key);
            for (String value : values) {
                out.println(key + "=" + value);
            }
        }*/
    }
}
